package com.university.trade.task;

import java.util.Date;

import javax.annotation.Resource;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.university.trade.service.BloggerService;
import com.university.trade.service.UserinfoService;
import com.university.trade.util.DateUtil;
import com.university.trade.util.PropertiesUtil;
import com.university.trade.util.ZipFileUtils;  
/**
 * 注解的方式实现定时任务  
 * @author yaojinshan
 *	2016-10-18 17:58
 */
@Component("taskJob2")  
public class TaskJob2 {  
	@Resource
	private UserinfoService userinfoService;
	@Resource
	private BloggerService bloggerService;
    
	@Scheduled(cron = "0 0 12 * * ?")  
    public void job1() {  
        System.out.println("任务2进行中。。。"); 
        System.out.println(bloggerService.find());
    }  
	/**
	 * 产品图片备份 
	 * 2016-10-31 yaojinshan
	 * @throws Exception
	 */
	@Scheduled(cron = "0 59 11 * * ?")  
	public void productImageBackup() throws Exception {  
		System.out.println("------图片备份开始-------------"); 
		PropertiesUtil systemProperties = new PropertiesUtil("/systemConfig.properties");
		String dateStr = DateUtil.formatDate(new Date(), "yyyyMMdd");
		String system_open_test = systemProperties.getProperty("system_open_test");//是否打开测试环境
		if("T".equals(system_open_test)){
			String local_image_dir = systemProperties.getProperty("local_image_dir");
			String local_image_backup_dir = systemProperties.getProperty("local_image_backup_dir");
			String local_image_backup_filename = systemProperties.getProperty("local_image_backup_filename");
			//String rootpath = TaskJob2.class.getClassLoader().getResource("").getPath();//项目发布路径
			//ZipFileUtils.createZip(rootpath + local_image_dir,rootpath + local_image_backup_dir+local_image_backup_filename+dateStr+".zip");
			ZipFileUtils.createZip(local_image_dir,local_image_backup_dir+local_image_backup_filename+dateStr+".zip");
		}else{
			String server_image_dir = systemProperties.getProperty("server_image_dir");
			String server_image_backup_dir = systemProperties.getProperty("server_image_backup_dir");
			String server_image_backup_filename = systemProperties.getProperty("server_image_backup_filename");
			String rootpath = TaskJob2.class.getClassLoader().getResource("").getPath();//项目发布路径
			ZipFileUtils.createZip(rootpath + server_image_dir,rootpath + server_image_backup_dir+server_image_backup_filename+dateStr+".zip");
		}
		System.out.println("------图片备份结束-------------"); 
	}  
} 
